home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1991 / number2 / font.cpp < prev    next >
C/C++ Source or Header  |  1991-03-08  |  2KB  |  89 lines

  1. //-------------------------------------------------------------//
  2. // File:   Font.Cpp                                            //
  3. // Desc:   Methods for Font and Character Classes              //
  4. // Author: Marv Luse, Autumn Hill Software                     //
  5. //-------------------------------------------------------------//
  6.  
  7. #include "font.hpp"
  8.  
  9. //........ default constructor
  10.  
  11. Font::Font( )
  12. {
  13.      fstatus = fntNOINIT;
  14.      cell_w = cell_h = 0;
  15.      ascent = descent = 0;
  16.      pitch = 0;
  17.      ch_cnt = 0;
  18.      min_ch = max_ch = 0;
  19.      ch = 0;
  20. }
  21.  
  22. //........ constructor that allocates char array
  23.  
  24. Font::Font( int bgn_ch, int end_ch )
  25. {
  26.      fstatus = fntNOINIT;
  27.      cell_w = cell_h = 0;
  28.      ascent = descent = 0;
  29.      pitch = 0;
  30.      ch_cnt = end_ch - bgn_ch + 1;
  31.      min_ch = bgn_ch;
  32.      max_ch = end_ch;
  33.      ch = new Character[ch_cnt];
  34.      if( ch == 0 )
  35.         fstatus = fntFAILED;
  36. }
  37.  
  38. //........ destructor
  39.  
  40. Font::~Font( )
  41. {
  42.      if( ch )
  43.         delete [ch_cnt] ch;
  44. }
  45.  
  46. //........ compute string width
  47.  
  48. int Font::strwidth( char *str )
  49. {
  50.      int w = 0;
  51.      while( *str )
  52.      {
  53.         if( (*str >= min_ch) && (*str <= max_ch) )
  54.            w += ch[*str-min_ch].delta_x;
  55.         str++;
  56.      }
  57.      return w;
  58. }
  59.  
  60. //........ compute actual string height
  61.  
  62. int Font::strheight( char *str )
  63. {
  64.      int h = 0;
  65.      while( *str )
  66.      {
  67.         if( (*str >= min_ch) && (*str <= max_ch) )
  68.            if( ch[*str-min_ch].height > h )
  69.               h = ch[*str-min_ch].height;
  70.         str++;
  71.      }
  72.      return h;
  73. }
  74.  
  75. //........ draw a string using Character.draw method
  76.  
  77. void Font::drawstr( int x, int y, int clr, char *str )
  78. {
  79.      while( *str )
  80.      {
  81.         if( (*str >= min_ch) && (*str <= max_ch) )
  82.         {
  83.            ch[*str-min_ch].drawch( x, y, clr );
  84.            x += ch[*str-min_ch].delta_x;
  85.         }
  86.         str++;
  87.      }
  88. }
  89.